<?php
ini_set("display_errors","On");
// 设置允许其他域名访问
header('Access-Control-Allow-Origin:http://localhost:8080');
// 设置允许的响应类型 
header('Access-Control-Allow-Methods:POST, GET');
// 设置允许的响应头 
header('Access-Control-Allow-Headers:x-requested-with,content-type');
// 响应头表示是否可以将对请求的响应暴露给页面
header('Access-Control-Allow-Credentials: true');
$json = file_get_contents("php://input");
$arr = json_decode($json,true);
include "config.php";
$key = $arr["key"];
$value = $arr["value"];
$type = $arr["type"];
if($type == "string"){
    $result = $redis->set($key,$value);
}elseif($type == "list"){
    $redis->del($key);
    $listArr = explode(',',$value);
    foreach($listArr as $v){
        $result = $redis->rpush($key,$v);
    }
}elseif($type == "hash"){
    foreach($arr["value"] as $k=>$v){
        $result = $redis->hset($key,$k,$v);
    }
}elseif($type == "set"){
    $redis->del($key);
    $listArr = explode(',',$value);
    foreach($listArr as $v){
        $result = $redis->sadd($key,$v);
    }
}elseif($type == "zset"){
    $resultArr = array();
    foreach($value as $k=>$v){
        $result = $redis->zadd($key,$k,$v);
    }
}
echo $result;